package cn.study.luckyapp.assembler;

import cn.study.luckyclient.dto.RuleAddCmd;
import cn.study.luckyclient.dto.RuleUpdateCmd;
import cn.study.luckyclient.dto.data.RuleVo;
import cn.study.luckydomain.rule.MinNum;
import cn.study.luckydomain.rule.RuleEntity;

import java.time.LocalDateTime;

public class RuleAssembler {
    public static RuleEntity toEntity(RuleAddCmd ruleAddCmd){
        RuleEntity ruleEntity = new RuleEntity();
        ruleEntity.setRuleName(ruleAddCmd.getRuleName());
        ruleEntity.setMaxJoinNumber(new MinNum(ruleAddCmd.getMaxJoinNumber()));
        ruleEntity.setMaxWinningNumber(new MinNum(ruleAddCmd.getMaxWinningNumber()));
        ruleEntity.setCreateTime(LocalDateTime.now());
        ruleEntity.setCretor("小三");
        ruleEntity.setUpdateTime(LocalDateTime.now());
        ruleEntity.setUpdater("小三");
        return ruleEntity;
    }
    public static RuleVo toRuleVo(RuleEntity ruleEntity){
        RuleVo ruleVo = new RuleVo();
        ruleVo.setId(ruleEntity.getId());
        ruleVo.setRuleName(ruleEntity.getRuleName());
        ruleVo.setMaxJoinNumber(ruleEntity.getMaxJoinNumber().getNumber());
        ruleVo.setMaxWinningNumber(ruleEntity.getMaxJoinNumber().getNumber());
        ruleVo.setCreateTime(ruleEntity.getCreateTime());
        ruleVo.setCretor(ruleEntity.getCretor());
        ruleVo.setUpdateTime(ruleEntity.getUpdateTime());
        ruleVo.setUpdater(ruleEntity.getUpdater());
        return ruleVo;
    }
    public static RuleEntity toEntity(RuleUpdateCmd ruleUpdateCmd){
        RuleEntity ruleEntity = new RuleEntity();
        ruleEntity.setId(ruleUpdateCmd.getId());
        ruleEntity.setRuleName(ruleUpdateCmd.getRuleName());
        ruleEntity.setMaxJoinNumber(new MinNum(ruleUpdateCmd.getMaxJoinNumber()));
        ruleEntity.setMaxWinningNumber(new MinNum(ruleUpdateCmd.getMaxWinningNumber()));
        ruleEntity.setCreateTime(LocalDateTime.now());
        ruleEntity.setCretor("小三");
        ruleEntity.setUpdateTime(LocalDateTime.now());
        ruleEntity.setUpdater("小三");
        return ruleEntity;
    }
}
